package cn.stu.projectsummit.likes.service.impl;

import cn.stu.projectsummit.base.response.JsonResult;
import cn.stu.projectsummit.likes.mapper.LikesMapper;
import cn.stu.projectsummit.likes.pojo.dto.SaveLikesParam;
import cn.stu.projectsummit.likes.pojo.entity.Likes;
import cn.stu.projectsummit.likes.pojo.vo.LikeVO;
import cn.stu.projectsummit.likes.service.LikesService;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import java.util.List;

@Service
@Slf4j
public class LikesServiceImpl implements LikesService {
    @Autowired
    LikesMapper likesMapper;

    @Override
    public void save(Long blogId, Long userId) {
        log.info("点赞业务: blogId={}", blogId);
        SaveLikesParam saveLikesParam = new SaveLikesParam();
        saveLikesParam.setBlogId(blogId);
        saveLikesParam.setUserId(userId);
        saveLikesParam.setCreateTime(new Date());
        likesMapper.save(saveLikesParam);
    }

    @Override
    public void delete(Long blogId, Long userId) {
        log.debug("取消点赞: blogId={},userId={}", blogId, userId);
        likesMapper.delete(blogId, userId);
    }

    @Override
    public List<Likes> select(Long userId) {
        return likesMapper.selectByUserId(userId);
    }

    @Override
    public Integer selectByBlogId(Long blogId) {
        return likesMapper.selectByBlogId(blogId);
    }

    @Override
    public List<Likes> selectByBlogIdList(List<Long> likeCountBlogIdList) {
        return likesMapper.selectByBlogIdList(likeCountBlogIdList);
    }



    @Override
    public List<LikeVO> select() {
        List<LikeVO> list = likesMapper.select();
        return list;
    }

    @Override
    public void deleteLikes(Long likeId) {
        likesMapper.deleteLikes(likeId);
    }


}

